<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 瑱彬
  Date: 2015/5/28
  Time: 19:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String context = request.getContextPath(); %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="<%=context%>/thirdparts/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="<%=context%>/thirdparts/bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet" type="text/css" href="<%=context%>/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="<%=context%>/css/publish.css"/>

    <link href="<%=context%>/thirdparts/ueditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">

    <script type="text/javascript" src="<%=context%>/js/jquery.min.js"></script>
    <script type="text/javascript" src="<%=context%>/thirdparts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=context%>/thirdparts/ueditor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=context%>/thirdparts/ueditor/umeditor.min.js"></script>
    <script type="text/javascript" src="<%=context%>/thirdparts/ueditor/lang/zh-cn/zh-cn.js"></script>

    <title>发布页</title>

</head>
<body>

<c:import url="top.jsp">
    <c:param name="pageName" value="home"/>
</c:import>

<div class="center">
    <div class="centerContainer">
        <div class="publishContainer">
            <div class="publishTitle">发布内容</div>
            <form action="/blog/publish" method="post" class="publishForm">
                标题<br />
                <input type="text" name="title"/><br/>
                关键字<br />
                <input type="text" name="kword"/><br/>
                标签<br />
                <input type="text" name="tags"/><br/>
                来源<br />
                <input type="text" name="source"/><br/>
                原创类型 <br/>
                <select name="original">
                    <option value="0">转载</option>
                    <option value="1" selected="selected">原创</option>
                    <option value="2">伪原创</option>
                    <option value="4">翻译</option>
                </select><br/>
                分类 <br/>
                <select name="catid">
                    <c:forEach items="${categories}" var="cat">
                        <option value="${cat.id}">${cat.name}</option>
                    </c:forEach>
                </select>
            </form>
            <br />
            <script type="text/plain" id="myEditor" style="width:820px;height:240px;"> <p>这里我可以写一些输入提示</p> </script>
            <script type="text/javascript">
                //实例化编辑器
                var um = UM.getEditor('myEditor');
            </script>


            <script type="text/javascript">
                function publish() {
                    var content = UM.getEditor('myEditor').getContent();
                    var title = $("input[name='title']").val();
                    var kword = $("input[name='kword']").val();
                    var tags = $("input[name='tags']").val();
                    var source = $("input[name='source']").val();
                    var original = $("select[name='original']").val();
                    var catid = $("select[name='catid']").val();
                    console.log(content);

                    $.post('<%=context%>/blog/publish', {
                        content: content,
                        title: title,
                        kword: kword,
                        tags: tags,
                        source: source,
                        original: original,
                        catid: catid
                    }, function (data, textStatus, xhr) {
                        showTopBox("发布成功",function(){window.location.href=CONTEXT+"/home";})
                    });

                }

                function cancel(){
                    window.location.href=CONTEXT + "/home";
                }

            </script>
            <div class="formBottom">
                <a href="#" onclick="publish()" class="formBtn submitBtn">发布</a>
                <a href="#" onclick="cancel()" class="formBtn cancelBtn">取消</a>
            </div>

        </div>
    </div>
</div>

<c:import url="bottom.jsp"/>

</body>
</html>
